package net.llz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.llz.mapper.ProductMapper;
import net.llz.model.ProductDO;
import net.llz.service.ProductService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Trace
    @Tags({
            @Tag(key = "test-output", value = "returnedObj")
    })
    @Override
    public List<ProductDO> list() {

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return productMapper.selectList(new QueryWrapper<>());
    }

    @Trace
    @Tags(
            {
                    @Tag(key = "detail-input", value = "arg[0]"),
                    @Tag(key = "detail-output", value = "returnedObj")
            }
    )
    @Override
    public ProductDO detail(long productId) {

        return productMapper.selectOne(new QueryWrapper<ProductDO>().eq("id",productId));
    }
}
